#include <gtk/gtk.h>
#include <stdlib.h>

GtkWidget *window;
GtkWidget *table;
GtkWidget *entry;
GtkWidget *label;
GtkWidget *button;
char text[50];

void on_clicked(GtkWidget *widget, gpointer data)
{
    strcpy(text, gtk_entry_set_text(GTK_ENTRY(entry)));
    printf("You entered string is: %s\n", text);
}

int main(int argc, char *argv[])
{
    gtk_init(&argc, &argv);

    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(window), "Use of Text Box");

    table = gtk_table_new(3, 2, FALSE);

    label = gtk_label_new("Please enter here:");
    entry = gtk_entry_new();
    gtk_entry_set_max_length(GTK_ENTRY(entry), 50);

    button = gtk_button_new_with_label("Submit");

    gtk_container_add(GTK_CONTAINER(window), table);

    gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 10, 10);
    gtk_table_attach(GTK_TABLE(table), entry, 0, 2, 1, 2, GTK_FILL, GTK_FILL, 10, 10);
    gtk_table_attach(GTK_TABLE(table), button, 1, 2, 2, 3, GTK_FILL, GTK_FILL, 10, 10);

    g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(on_clicked), NULL);

    gtk_widget_show_all(window);

    gtk_main();

    return 0;
}